package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetPermissionInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取权限详情
func NewGetPermissionInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPermissionInfoLogic {
	return &GetPermissionInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetPermissionInfoLogic) GetPermissionInfo(req *types.GetPermissionInfoRequest) (resp *types.GetPermissionInfoResponse, err error) {
	reply, err := l.svcCtx.AuthRoleRpc.GetPermissionInfo(l.ctx, &v1.GetPermissionInfoRequest{Id: req.Id})
	if err != nil {
		return nil, err
	}

	return &types.GetPermissionInfoResponse{
		Id:                   reply.GetId(),
		PermissionPid:        reply.GetPermissionPid(),
		PermissionName:       reply.GetPermissionName(),
		PermissionIdentifier: reply.GetPermissionIdentifier(),
		ListOrder:            reply.GetListOrder(),
		Status:               int8(reply.GetStatus()),
		CreatedAt:            reply.GetCreatedAt(),
		UpdatedAt:            reply.GetUpdatedAt(),
	}, err
}
